package com.falcon.modules.domain.bo;

import com.falcon.modules.domain.dto.Menu;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MenuBo implements Serializable, Comparable<MenuBo> {
    private String id;
    private String text;
    private List<MenuBo> menu;
    private List<MenuBo> items;
    private String href;
    private String homePage;
    private Boolean closeable;
    @JsonIgnore
    private Integer sort;


    public MenuBo(Menu menu) {
        if (menu.getHomePage() != null && menu.getHomePage()) {
            this.id = menu.getUrl();
        } else {
            this.id = "" + menu.getId();
        }
        this.text = menu.getName();
        this.sort = menu.getSort() == null ? 0 : menu.getSort();
        if (menu.getHomePage() != null && menu.getHomePage()) {
            this.homePage = menu.getUrl();
        }
        if (menu.getType() == 3) {
            this.closeable = menu.getHomePage() != null && menu.getHomePage() ? false : true;
            this.href = menu.getUrl();
        }
    }

    @Override
    public int compareTo(MenuBo o) {
        if (o == null) {
            return 1;
        }
        if (this.sort > o.sort) {
            return 1;
        }
        if (this.sort < o.sort) {
            return -1;
        }
        return 0;
    }
}
